package com.liangzhong.modules.activity.mediator
{
	import com.common.queueloader.QueueLoader;
	import com.common.queueloader.QueueLoaderEvent;
	import com.common.queueloader.QueueVo;
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.liangzhong.constants.ResourceConst;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.manager.ResourceManager;
	import com.liangzhong.mediator.ModuleMediator;
	import com.liangzhong.model.AppData;
	import com.liangzhong.proxyconstant.activity.ActivityConst;
	import com.lz.football.module.activity.IQzoneView;
	import com.lz.football.module.base.IModuleView;
	
	import flash.display.DisplayObject;
	
	import lz.controls.managers.PopUpManager;
	
	import org.puremvc.as3.interfaces.INotification;

	/**
	 *QQ空间相关  黄钻特权  
	 * @author lake
	 * 
	 */	
	public class QzoneMediator extends ModuleMediator
	{
		public static const MediatorName:String= "QzoneMediator";
		
		public function QzoneMediator(mediatorName:String=null, viewComponent:Object=null, param:Object=null)
		{
			super(mediatorName, viewComponent, param);
		}
		/**
		 *获取 实例 
		 * @return 
		 * 
		 */		
		public function get view():IQzoneView
		{
			return viewComponent as IQzoneView;
		}
		/**
		 *添加事件 
		 * 
		 */		
		override public function addEventListeners():void
		{
			(view as DisplayObject).addEventListener(ModuleEvent.REMOVE_MODULE,onRemoveModule);
		}
		/**
		 * 删除事件 
		 * 
		 */
		override public function removeEventListeners():void
		{
			(view as DisplayObject).removeEventListener(ModuleEvent.REMOVE_MODULE,onRemoveModule);
		}
		/**
		 *删除 
		 * @param e
		 * 
		 */		
		protected function onRemoveModule(e :ModuleEvent):void
		{
			removeMediator();
		}
		/**
		 * 监听信息
		 * @return 
		 * 
		 */		
		override public function listNotificationInterests():Array
		{
			return [];
		}
		/**
		 * 处理信息
		 * @param notification
		 * 
		 */		
		override public function handleNotification(notification:INotification):void
		{
			switch(notification.getName())
			{
				
				
			}
		}
		/**
		 * 
		 * 注册
		 */		
		override public function onRegister():void
		{
			
			if(ResourceManager.instance.isContainResource(ResourceConst.QZONE_SWF))
			{
				showUI();
			}
			else
			{
				loader = new QueueLoader();
				var clubConfig :XML = XML(ResourceManager.instance.getResource(ResourceConst.MODULE_RES_CONFIG)).qzone[0];
				bytesTotal = int(clubConfig.@totalBytes);
				var releaseVersion :String;
				for each(var item :XML in clubConfig.item)
				{
					releaseVersion = "?" + item.@version + "." + item.@itemType;
					loader.addQueue(new QueueVo(item.@resName,item.@id,item.@id),item.@url + releaseVersion);
				}
				loadRes();
			}
		}
		/**
		 *加载资源完毕 
		 * @param e
		 * 
		 */		
		override protected function onLoadComplete(e:QueueLoaderEvent):void
		{
			super.onLoadComplete(e);
			showUI();
			ResourceManager.instance.putResource(ResourceConst.QZONE_SWF,resList);
		}
		/**
		 *显示界面 
		 */		
		private function showUI():void
		{
			var cView :IModuleView = Reflection.createInstance("com.lz.football.module.activity.qzone.QzoneView");
			cView.initUI();
			viewComponent = cView;
			PopUpManager.addPopUp(view as DisplayObject,GlobalDef.GameWindowContainer,GlobalDef.GameStage.stageWidth,GlobalDef.GameStage.stageWidth,false);
			addEventListeners();
			if(AppData.getInstance().activityDatemanager.qzoneVo.isReq == false)
			{
				this.sendNotification(ActivityConst.QZONE_GET_INFO);
			}
		}
		/**
		 * 删除 mediator
		 * 
		 */		
		override public function removeMediator():void
		{
			facade.removeMediator(MediatorName);
		}
		/**
		 *删除 清理 
		 * 
		 */		
		override public function onRemove():void
		{
			super.onRemove();
			removeEventListeners();
			view.destroyView();
			viewComponent = null;
		}
	}
}